//
//  KZEveryDayViewController.m
//  xiaorizi
//
//  Created by kun on 15/10/23.
//  Copyright © 2015年 origin. All rights reserved.
//

#import "KZEveryDayViewController.h"
#import "KZGlobalApi.h"
#import "EveryDayModel.h"
#import "KZEveryDayCell.h"
#import "UITableView+buttonClicked.h"
#import "KZEveryDvdWebController.h"
#import "KZEventsViewController.h"

@interface KZEveryDayViewController ()

@end

@implementation KZEveryDayViewController

- (void)viewDidLoad {
    

    [super viewDidLoad];
    
}

- (void)downloadDataPath
{
    self.url = [KZGlobalApi meitianUrl];
    self.cachePath = [KZGlobalApi meitianCachePath];
    self.refreshType = FLRefreshTypeAll;
}

//控制tabbar
//-(void) viewWillDisappear:(BOOL)animated
//{
//    [super viewWillDisappear:animated];
//    self.tabBarController.tabBar.hidden = YES;
//}
//
//-(void)viewWillAppear:(BOOL)animated
//{
//    [super viewWillAppear:animated];
//    self.tabBarController.tabBar.hidden = NO;
//}



//重写父类方法

-(NSString *)JsonModelPath
{
    return [[NSBundle mainBundle]pathForResource:@"meitian" ofType:@"json"];
}


- (id)createDataWithNode:(id)node
{
    EveryDayModel *model = [EveryDayModel initWithDic:node];
    
    return model;
}

-(NSArray *)createDataArray:(NSDictionary *)dic
{
    NSArray *arrayData = dic[@"list"];
    
    return arrayData;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    EveryDayModel *model = self.data[indexPath.row];
    return model.cellHeight;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    KZEveryDayCell *cell = [tableView dequeueReusableCellWithIdentifier:@"everyDayCell" forIndexPath:indexPath];
    
    EveryDayModel *model = self.data[indexPath.row];
    
    
    //block回调
    
    [cell setEventsButtonBlock:^(UITableViewCell *cell, EveryDayModel * model) {
        
        //self.tabBarController.hidesBottomBarWhenPushed = YES;
        [self performSegueWithIdentifier:@"meitian" sender:model];
        //self.hidesBottomBarWhenPushed = NO;
    }];
    
    [cell setImgButtonBlock:^(UITableViewCell * cell, NSString *themeUrl) {
        
       // self.hidesBottomBarWhenPushed = YES;
        [self performSegueWithIdentifier:@"meiji" sender:themeUrl];
       // self.hidesBottomBarWhenPushed = NO;
    }];
    
    cell.model = model;
    
    return cell;
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
  
    
    if([segue.identifier isEqualToString:@"meiji"])
    {
       // self.tabBarController.hidesBottomBarWhenPushed  = YES;
        NSString *themeUrl = sender;
        KZEveryDvdWebController *webVc = [segue destinationViewController];
        webVc.themeurl = themeUrl;
        
    }
    
    if([segue.identifier isEqualToString:@"meitian"])
    {
        KZEventsViewController *eventVc = [segue destinationViewController];
        eventVc.model = sender;
    }
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
